home *** CD-ROM | disk | FTP | other *** search
- class smashing.keithm.Viewport
- {
- static var __a_groups;
- static var __o_groups;
- static var __dimensions;
- static var __viewportPath;
- static var __viewportDepth;
- static var __useScrollport;
- static var __instance;
- static var __scrollportDepth;
- static var mc;
- static var scrollmc;
- static var __defaultMCDepth = 100;
- function Viewport(t_path, t_depth, dimensions)
- {
- smashing.keithm.Viewport.__a_groups = [];
- smashing.keithm.Viewport.__o_groups = {};
- smashing.keithm.Viewport.__dimensions = dimensions;
- smashing.keithm.Viewport.__viewportPath = t_path;
- smashing.keithm.Viewport.__viewportDepth = t_depth;
- smashing.keithm.Viewport.__useScrollport = false;
- trace("-- Init Viewport --");
- }
- static function init(t_path, t_depth, dimensions)
- {
- smashing.keithm.Viewport.__instance = new smashing.keithm.Viewport(t_path,t_depth,dimensions);
- }
- static function getInstance()
- {
- return smashing.keithm.Viewport.__instance;
- }
- function setScrollport(t_depth)
- {
- smashing.keithm.Viewport.__useScrollport = true;
- smashing.keithm.Viewport.__scrollportDepth = t_depth;
- }
- function reset()
- {
- var _loc6_ = smashing.keithm.Viewport.__a_groups.length;
- var _loc2_ = undefined;
- var _loc5_ = [];
- var _loc3_ = 0;
- while(_loc5_.length < _loc6_)
- {
- _loc2_ = smashing.keithm.Viewport.__a_groups.length;
- while(true)
- {
- _loc2_;
- if(!_loc2_--)
- {
- break;
- }
- if(smashing.keithm.Viewport.__a_groups[_loc2_].index < smashing.keithm.Viewport.__a_groups[_loc3_].index)
- {
- _loc3_ = _loc2_;
- }
- }
- _loc5_.push(smashing.keithm.Viewport.__a_groups[_loc3_]);
- smashing.keithm.Viewport.__a_groups.splice(_loc3_,1);
- }
- smashing.keithm.Viewport.__a_groups = _loc5_;
- var _loc4_ = smashing.keithm.Viewport.__defaultMCDepth;
- _loc2_ = 0;
- while(_loc2_ < smashing.keithm.Viewport.__a_groups.length)
- {
- _loc4_ = smashing.keithm.Viewport.__a_groups[_loc2_].init(_loc4_);
- _loc4_ = _loc4_ + 1;
- _loc2_ = _loc2_ + 1;
- }
- this.newView();
- }
- function newView()
- {
- var _loc1_ = smashing.keithm.Viewport.__a_groups.length;
- while(true)
- {
- _loc1_;
- if(!_loc1_--)
- {
- break;
- }
- smashing.keithm.Viewport.__a_groups[_loc1_].reset();
- }
- if(smashing.keithm.Viewport.mc != undefined)
- {
- smashing.keithm.Viewport.mc.removeMovieClip();
- }
- smashing.keithm.Viewport.mc = smashing.keithm.Viewport.__viewportPath.createEmptyMovieClip("viewport" + smashing.keithm.Viewport.__viewportDepth,smashing.keithm.Viewport.__viewportDepth);
- if(smashing.keithm.Viewport.__useScrollport)
- {
- if(smashing.keithm.Viewport.scrollmc != undefined)
- {
- smashing.keithm.Viewport.scrollmc.removeMovieClip();
- }
- smashing.keithm.Viewport.scrollmc = smashing.keithm.Viewport.__viewportPath.createEmptyMovieClip("scrollport" + smashing.keithm.Viewport.__scrollportDepth,smashing.keithm.Viewport.__scrollportDepth);
- smashing.keithm.Viewport.scrollmc.scrollRect = new flash.geom.Rectangle(0,0,smashing.keithm.Viewport.__dimensions.SCREEN_WIDTH + 1,smashing.keithm.Viewport.__dimensions.SCREEN_HEIGHT);
- }
- }
- function clearGroup(t_group)
- {
- var _loc2_ = smashing.keithm.Viewport.__o_groups[t_group].mcs;
- while(_loc2_.length > 0)
- {
- this.__eraseAsset(_loc2_[0].mc,t_group);
- }
- }
- function draw(t_data)
- {
- var _loc4_ = undefined;
- if(t_data.element != undefined)
- {
- var _loc3_ = t_data.element;
- if(!_loc3_.isSpawned)
- {
- trace("WARNING: despawned entity " + _loc3_.assetID + " received draw request.");
- return undefined;
- }
- _loc4_ = this.__drawElement(_loc3_);
- if(_loc4_ != undefined)
- {
- _loc3_.onDraw(_loc4_,smashing.keithm.Viewport.getInstance());
- }
- trace("ERROR DRAWING ASSET " + _loc3_.assetID);
- return undefined;
- }
- if(t_data.assetID == "_empty")
- {
- return this.__drawEmpty(t_data.groupName,t_data.depth + t_data.depthInfluence);
- }
- return this.__drawAsset(t_data.assetID,t_data.groupName,t_data.depth + t_data.depthInfluence);
- }
- function erase(t_data)
- {
- if(t_data.element != undefined)
- {
- this.__eraseAsset(t_data.element.mc,t_data.element.getDrawType());
- t_data.element.onErase(smashing.keithm.Viewport.getInstance());
- }
- else
- {
- this.__eraseAsset(t_data.mc,t_data.groupName);
- }
- }
- function createGroup(t_data)
- {
- smashing.keithm.Viewport.__a_groups.push(smashing.keithm.Viewport.__o_groups[t_data.name] = new smashing.keithm.ViewportGroup(t_data));
- }
- function requestGroupDepthSort(t_group)
- {
- smashing.keithm.Viewport.__o_groups[t_group].requestDepthSort();
- }
- function requestDepthChange(t_element)
- {
- smashing.keithm.Viewport.__o_groups[t_element.getDrawType()].requestDepthChange(t_element);
- }
- function __drawElement(t_element)
- {
- var _loc5_ = undefined;
- var _loc2_ = smashing.keithm.Viewport.__o_groups[t_element.getDrawType()];
- var _loc7_ = _loc2_.getDepth(t_element[_loc2_.sortAxis] + t_element.depthInfluence);
- var _loc3_ = smashing.keithm.Viewport.mc;
- if(_loc2_.scrollport)
- {
- _loc3_ = smashing.keithm.Viewport.scrollmc;
- }
- if(t_element.assetID == "_empty")
- {
- var _loc4_ = _loc3_.createEmptyMovieClip(t_element.getDrawType() + _loc7_,_loc7_);
- }
- else
- {
- _loc4_ = _loc3_.attachMovie(t_element.assetID,t_element.assetID + _loc7_,_loc7_);
- }
- _loc2_.mcs.push({mc:_loc4_,depth:_loc7_});
- _loc5_.initScale();
- return _loc4_;
- }
- function __drawAsset(t_asset, t_groupName, t_depth)
- {
- var _loc1_ = smashing.keithm.Viewport.__o_groups[t_groupName];
- var _loc6_ = _loc1_.getDepth(t_depth);
- var _loc3_ = smashing.keithm.Viewport.mc;
- if(_loc1_.scrollport)
- {
- _loc3_ = smashing.keithm.Viewport.scrollmc;
- }
- var _loc2_ = _loc3_.attachMovie(t_asset,t_asset + _loc6_,_loc6_);
- _loc1_.mcs.push({mc:_loc2_,depth:_loc6_});
- return _loc2_;
- }
- function __drawEmpty(t_groupName, t_depth)
- {
- var _loc3_ = smashing.keithm.Viewport.__o_groups[t_groupName];
- var _loc6_ = _loc3_.getDepth(t_depth);
- var _loc2_ = smashing.keithm.Viewport.mc;
- if(_loc3_.scrollport)
- {
- _loc2_ = smashing.keithm.Viewport.scrollmc;
- }
- var _loc1_ = _loc2_.createEmptyMovieClip(t_groupName + _loc6_,_loc6_);
- smashing.keithm.Viewport.__o_groups[t_groupName].mcs.push({mc:_loc1_,depth:_loc6_});
- return _loc1_;
- }
- function __eraseAsset(t_mc, t_groupName)
- {
- var _loc2_ = smashing.keithm.Viewport.__o_groups[t_groupName];
- var _loc1_ = _loc2_.mcs.length;
- while(true)
- {
- _loc1_;
- if(!_loc1_--)
- {
- break;
- }
- if(_loc2_.mcs[_loc1_].mc == t_mc)
- {
- _loc2_.mcs[_loc1_].mc.removeMovieClip();
- _loc2_.mcs.splice(_loc1_,1);
- return undefined;
- }
- }
- }
- function toString()
- {
- return "Viewport exists";
- }
- }
-